package com.tarena.lbs.content.controller;

import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.content.pojo.param.ArticleCategoryParam;
import com.tarena.lbs.content.pojo.query.ArticleCategoryQuery;
import com.tarena.lbs.content.pojo.vo.ArticleCategoryVO;
import com.tarena.lbs.content.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 处理文章分类 业务模块功能
 */
@Api(tags = "文章分类管理")
@RestController
@Slf4j
public class CategoryController {
    @Autowired
    CategoryService categoryService;


    /**
     * 插入分类
     * ~
     * @return
     */
    @ApiOperation("文章分类列表查询")
    @GetMapping("/admin/content/category/list")
    public Result<PageResult<ArticleCategoryVO>> pageList(ArticleCategoryQuery query){
        log.debug("查询文章分类列表");
        PageResult<ArticleCategoryVO> pageResult = categoryService.pageList(query);
        Result<PageResult<ArticleCategoryVO>> Result = new Result<>("200", "操作成功", pageResult);
        return Result;
    }

    @ApiOperation("新增文章分类")
    @PostMapping("/admin/content/category/insert")
    public Result<Void> insert(ArticleCategoryParam categoryParam){
        log.debug("新增文章分类,参数{}",  categoryParam);
        categoryService.insert(categoryParam);
        return new Result<>("0", "操作成功", null) ;
    }

    @ApiOperation("修改文章分类")
    @PostMapping("/admin/content/category/update")
    public Result<Void> update(ArticleCategoryParam categoryParam){
        log.debug("修改文章分类,参数{}",  categoryParam);
        categoryService.insert(categoryParam);
        return new Result<>("0", "操作成功", null) ;
    }

    @ApiOperation("删除文章分类")
    @PostMapping("/admin/content/category/delete")
    public Result<Void> delete(@RequestBody ArticleCategoryParam categoryParam){
        log.debug("删除文章分类,参数{}",  categoryParam);
        categoryService.delete(categoryParam);
        return new Result<>("0", "操作成功", null) ;
    }

}
